package net.yla.smartbus.module.controller.web.ba.vehicletype;

import net.yla.smartbus.core.api.ApiResult;
import net.yla.smartbus.core.base.BaseController;
import net.yla.smartbus.core.base.PageBean;
import net.yla.smartbus.module.ba.vehicletype.dto.VehicleTypeDto;
import net.yla.smartbus.module.ba.vehicletype.form.VehicleTypeForm;
import net.yla.smartbus.module.ba.vehicletype.query.VehicleTypeQuery;
import net.yla.smartbus.module.ba.vehicletype.serice.VehicleTypeService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 默苍离
 * @date 2021/6/23 9:57
 * <p>
 * ******************************************
 * @annotation:
 */
@RestController
@RequestMapping("/api/web/taxi/ba")
public class VehicleTypeController extends BaseController {

    private final VehicleTypeService service;

    public VehicleTypeController(VehicleTypeService service) {
        this.service = service;
    }


    /**
     * 查询所有车辆类型
     *
     * @param query
     * @return
     */
    @PostMapping("/vehicleType/getList")
    public ApiResult getList(@RequestBody VehicleTypeQuery query) {
        PageBean<VehicleTypeDto> list = service.getPage(query);
        return success(list);
    }


    /**
     * 查询所有车辆类型
     *
     * @param ids
     * @return
     */
    @PostMapping("/vehicleType/delete")
    public ApiResult getList(@RequestBody Integer[] ids) {
        Integer delete = service.delete(ids);
        return success(delete);
    }


    /**
     * 新增车辆类型
     *
     * @param form
     * @return
     */
    @PostMapping("/vehicleType/insert")
    public ApiResult insert(@RequestBody VehicleTypeForm form) {

        if (form.getModelId() != null) {
            return success(service.update(form));
        }

        if (form.getBrandId() != null) {
            return success(service.insert(form));
        } else {
            return error(400, "缺少数据");
        }
    }


    /**
     * 根据id查找车辆类型
     *
     * @param id
     * @return
     */
    @PostMapping("/vehicleType/getVehicleTypeById")
    public ApiResult getVehicleTypeById(Integer id) {
        VehicleTypeDto vehicleTypeById = service.getVehicleTypeById(id);
        return success(vehicleTypeById);
    }


}
